package com.hua.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;
import com.hua.utils.PageDataSource;

public class StringServlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		response.setContentType("text/html;charset=utf-8");
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");// 设置编码
		PrintWriter write = response.getWriter();
		int pageNum = Integer.parseInt(request.getParameter("pageNum"));

		List<String> list = PageDataSource.getDataSourceString(pageNum);
		Map<String, List<String>> map = new HashMap<String, List<String>>();
		map.put("news", list);
		write.println(JSON.toJSONString(map));
		write.flush();
		write.close();
	}

}
